
package sumo.box;

import org.newdawn.slick.SlickException;


public class Desfazer {
    //vetor numa ca classe que vai gravando os ultimos movimentos.. heroDir, bombDir, etc.., 
    //grava no vetor a cada movimento. não grava nada se o heroi nao se mexer
    
    private static String move[] = new String[10];
    private static Bomba[] bomb = new Bomba[10];
    
    public static void setBomb(Bomba bomba){
        System.arraycopy(bomb, 0, bomb, 1, 9);
        bomb[0] = bomba;
    }
    public static void subBomb(){
        for(int k=0; k<9; k++){
            bomb[k] = bomb[k+1];
            bomb[9] = null;
        }
    }
    public static void setMove(String valor){
        System.arraycopy(move, 0, move, 1, 9);
        move[0] = valor;
    }
    public static void subMove(){
        for(int k=0; k<9; k++){
            move[k] = move[k+1];
            move[9] = null;
        }
        
    }
    public static void undo(Personagem hero, Bomba[] bombs, Lugar[] places) throws SlickException{
        if("heroEsq".equals(move[0])){
            hero.addX(40);
            hero.subMovs();
            hero.setImg("esq0"+(hero.getMovs()%3)+".png");
            subMove();
        }
        else if("heroDir".equals(move[0])){
            hero.addX(-40);
            hero.subMovs();
            hero.setImg("dir0"+(hero.getMovs()%3)+".png");
            subMove();
            
        }
        else if("heroCima".equals(move[0])){
            hero.addY(40);
            hero.subMovs();
            hero.setImg("cima0"+(hero.getMovs()%3)+".png");
            subMove();
        }
        else if("heroBaixo".equals(move[0])){
            hero.addY(-40);
            hero.subMovs();
            hero.setImg("baixo0"+(hero.getMovs()%3)+".png");
            subMove();
        }
        
        else if("bombEsq".equals(move[0])){
            if(PlaceTest.test(places, bomb[0].getX(), bomb[0].getY())){
                    Lugar lugar = PlaceTest.qualLugar(places,bomb[0].getX(),bomb[0].getY());
                    bomb[0].setImg("src/IMAGES/bomb00.png");
                    lugar.unDone();
            }
            if(PlaceTest.test(places, bomb[0].getX()+40, bomb[0].getY())){
                    Lugar lugar = PlaceTest.qualLugar(places, bomb[0].getX()+40, bomb[0].getY());
                    bomb[0].setImg("src/IMAGES/bomb01.png");
                    lugar.Done();
            }
            bomb[0].addX(40);
            hero.addX(40);
            hero.subMovs();
            hero.setImg("esq0"+(hero.getMovs()%3)+".png");
            subMove();
            subBomb();
        }
        
        
        else if("bombDir".equals(move[0])){
            if(PlaceTest.test(places, bomb[0].getX(), bomb[0].getY())){
                    Lugar lugar = PlaceTest.qualLugar(places,bomb[0].getX(),bomb[0].getY());
                    bomb[0].setImg("src/IMAGES/bomb00.png");
                    lugar.unDone();
            }
            if(PlaceTest.test(places, bomb[0].getX()-40, bomb[0].getY())){
                    Lugar lugar = PlaceTest.qualLugar(places, bomb[0].getX()-40, bomb[0].getY());
                    bomb[0].setImg("src/IMAGES/bomb01.png");
                    lugar.Done();
            }
            bomb[0].addX(-40);
            hero.addX(-40);
            hero.subMovs();
            hero.setImg("dir0"+(hero.getMovs()%3)+".png");
            subMove();
            subBomb();
        }
        
        else if("bombCima".equals(move[0])){
            if(PlaceTest.test(places, bomb[0].getX(), bomb[0].getY())){
                    Lugar lugar = PlaceTest.qualLugar(places,bomb[0].getX(),bomb[0].getY());
                    bomb[0].setImg("src/IMAGES/bomb00.png");
                    lugar.unDone();
            }
            if(PlaceTest.test(places, bomb[0].getX(), bomb[0].getY()+40)){
                    Lugar lugar = PlaceTest.qualLugar(places, bomb[0].getX(), bomb[0].getY()+40);
                    bomb[0].setImg("src/IMAGES/bomb01.png");
                    lugar.Done();
            }
            bomb[0].addY(40);
            hero.addY(40);
            hero.subMovs();
            hero.setImg("cima0"+(hero.getMovs()%3)+".png");
            subMove();
            subBomb();
        }
        
        else if("bombBaixo".equals(move[0])){
            if(PlaceTest.test(places, bomb[0].getX(), bomb[0].getY())){
                    Lugar lugar = PlaceTest.qualLugar(places,bomb[0].getX(),bomb[0].getY());
                    bomb[0].setImg("src/IMAGES/bomb00.png");
                    lugar.unDone();
            }
            if(PlaceTest.test(places, bomb[0].getX(), bomb[0].getY()-40)){
                    Lugar lugar = PlaceTest.qualLugar(places, bomb[0].getX(), bomb[0].getY()-40);
                    bomb[0].setImg("src/IMAGES/bomb01.png");
                    lugar.Done();
            }
            bomb[0].addY(-40);
            hero.addY(-40);
            hero.subMovs();
            hero.setImg("baixo0"+(hero.getMovs()%3)+".png");
            subMove();
            subBomb();
        }
    }
    
    
    
    
   
}
